<html>
<script>
function add () {
    var args = Array.prototype.slice.call(arguments);
 
    var fn = function () {
        var arg_fn = Array.prototype.slice.call(arguments);
        return add.apply(null, args.concat(arg_fn));
    }
 
    fn.valueOf = function () {
        debugger;
        console.log("fn.valueOf called!!: " + args);
        return args.reduce(function(a, b) {
            var arg_fn = Array.prototype.slice.call(arguments);
            console.log("in reduce: " + arg_fn);
            return a + b;
        })
    }
    return fn;
}

add(1);
add(1)(2);
console.log(add(1)(2)(3)(4)(5));
</script>
</html>